package club.janna.rpcdemo.client.config;

import club.janna.rpcdemo.client.discover.ServiceDiscover;
import club.janna.rpcdemo.client.discover.StaticServiceDiscover;
import club.janna.rpcdemo.client.discover.ZooKeeperServiceDiscover;
import club.janna.rpcdemo.client.invoke.NetInvoker;
import club.janna.rpcdemo.client.invoke.TCPNetInvoker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Configuration
public class RPCConfig {
    @Value("${transport.protocol}")
    private String protocol;
    @Value("${discover.zookeeper:''}")
    private String zookeeperAddress;

    @Bean
    public NetInvoker netInvoker() {
        return new TCPNetInvoker();
    }

    @Bean
    public ServiceDiscover serviceDiscover() {
        if(StringUtils.isEmpty(zookeeperAddress))
            return new StaticServiceDiscover();
        else
            return new ZooKeeperServiceDiscover(zookeeperAddress);
    }
}
